﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Nop.Core.Domain.Customers
{
    public abstract class BaseNameExtensions : INameExtensions
    {
        protected readonly IDictionary<int, string> idToValues;

        protected BaseNameExtensions(IDictionary<int, string> idToValues)
        {
            this.idToValues = idToValues;
        }

        public virtual IEnumerable<int> Ids()
        {
            return idToValues.Keys;
        }

        public virtual IEnumerable<string> AllExtensions()
        {
            return idToValues.Values;
        }

        public virtual string GetValue(int id)
        {
            if (idToValues.ContainsKey(id))
            {
                return idToValues[id];
            }
            throw new ArgumentException("Invalid id");
        }

        public virtual int GetIdByValue(string value)
        {
            return idToValues.FirstOrDefault(x => x.Value == value).Key;
        }
    }
}
